******* Stata code for "Social Status and Prosocial Behavior" Zheng, Schram and Song *******
*                                                                                          *
*                                                                                          *
*                                                                                          *
********************************************************************************************

***** Main variable labels *****
// treatment variables: 
*           Baseline treatment: treatment == 3                               
*           Random status treatment: treatment == 2                                 
*           Earned status treatment: treatment == 1    
*           'type': 1 Baseline
*                   2 Random low status
*                   3 Random high status
*                   4 Earned low status
*                   5 Earned high status

//In regressions
*           'RSLow': random low status players
*           'RSHigh': random high status players
*           'ESLow': earned low status players
*           'ESHigh': earned high status players
*           'Low': low status players
*           'High': high status players
*           'type1': 1 if baseline
*                    2 if low status
*                    3 if high status
*           'cho': chosen effort by player 2
*           'un': unique session id
*           'gender': dummy, 1 if female, 0 if male
*           'clever': attitude towards the statement of "People with stars in my experiment session are more clever." 1 (totally disagree) to 7 (totally agree).
*           'ability': attitude towards the statement of "The method to allocate stars reflects abilities." 1 (totally disagree) to 7 (totally agree).
*           'deserving': attitude towards the statement of "People with stars in my experiment session deserve to get more in team-production task." 1 (totally disagree) to 7 (totally agree).
*           'guess': the belief on other player's behavior (incentivised question in the survey)

// status-related variables
*           high\low status: highstatus == 1/0     
*           player role in team-rpoduction task: player == 1/2
*           'proposal': player 1's suggestion to player 2 (what effort level p2 should exert)         
*           'effort1AS': player 2's response to player 1's suggestion of effort level 1 
*           'effort3AS': player 2's response to player 1's suggestion of effort level 3                 
*           'effort5AS': player 2's response to player 1's suggestion of effort level 5                
*           'effort7AS': player 2's response to player 1's suggestion of effort level 7                 
*           'effort9AS': player 2's response to player 1's suggestion of effort level 9  
*           'meanresponse': average response effort of player 2
*           'selfishnew': dummy, 1 if the response effort is always 1 (minimum) no matter what proposal is, 0 otherwise.
*           'deviate1AS': deviation level of the proposal, is defined by the difference between effort1AS and the actual proposal being 1         
*           'deviate3AS': deviation level of the proposal, is defined by the difference between effort3AS and the actual proposal being 3       
*           'deviate5AS': deviation level of the proposal, is defined by the difference between effort5AS and the actual proposal being 5
*           'deviate7AS': deviation level of the proposal, is defined by the difference between effort3AS and the actual proposal being 7
*           'deviate9AS': deviation level of the proposal, is defined by the difference between effort3AS and the actual proposal being 9       
*           'dev1stratAS': deviation level from the strategy method proposal at level 1       
*           'dev3stratAS': deviation level from the strategy method proposal at level 3  
*           'dev5stratAS': deviation level from the strategy method proposal at level 5
*           'dev7stratAS': deviation level from the strategy method proposal at level 7
*           'dev9stratAS': deviation level from the strategy method proposal at level 9      
       
// personal traits variables
*           conducting country China/ Netherlands: country == 0/1
*           'ppnr': personal id in each session
*           'study':  A -- economics and management 
*                     B -- sociology (social psychology related majors)
*                     C -- other sociology majors
*                     D -- natural sciences 
*                     E -- law
*                     F -- humanities
*                     G -- medicine
*                     H -- other majors
*                     econ -- UVA - Faculty of Economics and Business
*                     psy -- UVA - Faculty of Social and Behavioural Sciences - Psychology
*                     FMG -- UVA - Faculty of Social and Behavioural Sciences - non psychology
*                     NWI -- UVA - Faculty of Science
*                     betagamma -- UVA - IIS: beta gamma bachelor
*                     Rechten -- UVA - Faculty of Law
*                     Geestes -- UVA - Faculty of Humanities
*                     Genees -- UVA - Faculty of Medicine
*                     Tand -- UVA - Faculty of Dentistry
*                     andU -- Another university
*                     andH -- A Dutch 'hogeschool' (HBO)
*                     anders -- Other different places




use "..Pooled_data_April27.dta"

set seed 1973
//make new variable for chosen effort by player 2
//generate choseneffort2=0
//replace choseneffort2=effort1AS if proposal==1&player==2
//replace choseneffort2=effort3AS if proposal==3&player==2
//replace choseneffort2=effort5AS if proposal==5&player==2
//replace choseneffort2=effort7AS if proposal==7&player==2
//replace choseneffort2=effort9AS if proposal==9&player==2


//Make variable for player type
//generate type=0
//replace type=1 if treatment==3
//replace type=2 if treatment==2&clean==0
//replace type=3 if treatment==2&clean==1
//replace type=4 if treatment==1&clean==0
//replace type=5 if treatment==1&clean==1

//find mean effort per type and test for pairwise differences
mean cho if player==2, over(type)

permute cho (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==2), nodots reps(10000):ttest cho, by(type)
permute cho (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==3), nodots reps(10000):ttest cho, by(type)
permute cho (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==4), nodots reps(10000):ttest cho, by(type)
permute cho (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==5), nodots reps(10000):ttest cho, by(type)
permute cho (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==3), nodots reps(10000):ttest cho, by(type)
permute cho (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==4), nodots reps(10000):ttest cho, by(type)
permute cho (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==5), nodots reps(10000):ttest cho, by(type)
permute cho (r(mu_1)-r(mu_2)) if player==2&(type==3 | type==4), nodots reps(10000):ttest cho, by(type)
permute cho (r(mu_1)-r(mu_2)) if player==2&(type==3 | type==5), nodots reps(10000):ttest cho, by(type)
permute cho (r(mu_1)-r(mu_2)) if player==2&(type==4 | type==5), nodots reps(10000):ttest cho, by(type)

//pool low types and high types and test again

//generate type1=0
//replace type1=1 if type==1
//replace type1=2 if type==2|type==4
//replace type1=3 if type==3|type==5
permute cho (r(mu_1)-r(mu_2)) if player==2&(type1==1 | type1==2), nodots reps(10000):ttest cho, by(type1)
permute cho (r(mu_1)-r(mu_2)) if player==2&(type1==1 | type1==3), nodots reps(10000):ttest cho, by(type1)
permute cho (r(mu_1)-r(mu_2)) if player==2&(type1==2 | type1==3), nodots reps(10000):ttest cho, by(type1)

//find conditional means and test for differences
mean effort1AS effort3AS effort5AS effort7AS effort9AS  if player==2, over(type)
//generate meanresponse=(effort1AS+effort3AS+effort5AS+effort7AS+effort9AS)/5 if player==2

mean meanresponse if player==2, over(type)
permute meanresponse (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==2), nodots reps(10000):ttest meanresponse, by(type)
permute meanresponse (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==3), nodots reps(10000):ttest meanresponse, by(type)
permute meanresponse (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==4), nodots reps(10000):ttest meanresponse, by(type)
permute meanresponse (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==5), nodots reps(10000):ttest meanresponse, by(type)
permute meanresponse (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==3), nodots reps(10000):ttest meanresponse, by(type)
permute meanresponse (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==4), nodots reps(10000):ttest meanresponse, by(type)
permute meanresponse (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==5), nodots reps(10000):ttest meanresponse, by(type)
permute meanresponse (r(mu_1)-r(mu_2)) if player==2&(type==3 | type==4), nodots reps(10000):ttest meanresponse, by(type)
permute meanresponse (r(mu_1)-r(mu_2)) if player==2&(type==3 | type==5), nodots reps(10000):ttest meanresponse, by(type)
permute meanresponse (r(mu_1)-r(mu_2)) if player==2&(type==4 | type==5), nodots reps(10000):ttest meanresponse, by(type)

permute meanresponse (r(mu_1)-r(mu_2)) if player==2&(type1==1 | type1==2), nodots reps(10000):ttest meanresponse, by(type1)
permute meanresponse (r(mu_1)-r(mu_2)) if player==2&(type1==1 | type1==3), nodots reps(10000):ttest meanresponse, by(type1)
permute meanresponse (r(mu_1)-r(mu_2)) if player==2&(type1==2 | type1==3), nodots reps(10000):ttest meanresponse, by(type1)


//mean response if proposal<=5. UNUSED
//generate meanresponse5=(effort1AS+effort3AS+effort5AS)/3 if player==2

mean meanresponse5 if player==2, over(type)
permute meanresponse5 (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==2), nodots reps(10000):ttest meanresponse5, by(type)
permute meanresponse5 (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==3), nodots reps(10000):ttest meanresponse5, by(type)
permute meanresponse5 (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==4), nodots reps(10000):ttest meanresponse5, by(type)
permute meanresponse5 (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==5), nodots reps(10000):ttest meanresponse5, by(type)
permute meanresponse5 (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==3), nodots reps(10000):ttest meanresponse5, by(type)
permute meanresponse5 (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==4), nodots reps(10000):ttest meanresponse5, by(type)
permute meanresponse5 (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==5), nodots reps(10000):ttest meanresponse5, by(type)
permute meanresponse5 (r(mu_1)-r(mu_2)) if player==2&(type==3 | type==4), nodots reps(10000):ttest meanresponse5, by(type)
permute meanresponse5 (r(mu_1)-r(mu_2)) if player==2&(type==3 | type==5), nodots reps(10000):ttest meanresponse5, by(type)
permute meanresponse5 (r(mu_1)-r(mu_2)) if player==2&(type==4 | type==5), nodots reps(10000):ttest meanresponse5, by(type)

//Kolmogorv-Smirnov for effort response functions
use "../response functions.dta"
ksmirnov effort if type==1|type==2, by(type) exact
ksmirnov effort if type==1|type==3, by(type) exact
ksmirnov effort if type==1|type==4, by(type) exact
ksmirnov effort if type==1|type==5, by(type) exact
ksmirnov effort if type==2|type==3, by(type) exact
ksmirnov effort if type==2|type==4, by(type) exact
ksmirnov effort if type==2|type==5, by(type) exact
ksmirnov effort if type==3|type==4, by(type) exact
ksmirnov effort if type==3|type==5, by(type) exact
ksmirnov effort if type==4|type==5, by(type) exact

//does the response to a fair proposal differ?
use "../Pooled_data_April27.dta"
permute effort5AS (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==2), nodots reps(10000):ttest effort5AS, by(type)
permute effort5AS (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==3), nodots reps(10000):ttest effort5AS, by(type)
permute effort5AS (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==4), nodots reps(10000):ttest effort5AS, by(type)
permute effort5AS (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==5), nodots reps(10000):ttest effort5AS, by(type)
permute effort5AS (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==3), nodots reps(10000):ttest effort5AS, by(type)
permute effort5AS (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==4), nodots reps(10000):ttest effort5AS, by(type)
permute effort5AS (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==5), nodots reps(10000):ttest effort5AS, by(type)
permute effort5AS (r(mu_1)-r(mu_2)) if player==2&(type==3 | type==4), nodots reps(10000):ttest effort5AS, by(type)
permute effort5AS (r(mu_1)-r(mu_2)) if player==2&(type==3 | type==5), nodots reps(10000):ttest effort5AS, by(type)
permute effort5AS (r(mu_1)-r(mu_2)) if player==2&(type==4 | type==5), nodots reps(10000):ttest effort5AS, by(type)

//create selfishness dummy and test for differences
//generate selfishnew=0
//replace selfishnew=1 if effort1AS+effort3AS+effort5AS+effort7AS+effort9AS==5

mean selfishnew if player==2, over(type)

permute selfishnew (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==2), nodots reps(10000):ttest selfishnew, by(type)
permute selfishnew (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==3), nodots reps(10000):ttest selfishnew, by(type)
permute selfishnew (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==4), nodots reps(10000):ttest selfishnew, by(type)
permute selfishnew (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==5), nodots reps(10000):ttest selfishnew, by(type)
permute selfishnew (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==3), nodots reps(10000):ttest selfishnew, by(type)
permute selfishnew (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==4), nodots reps(10000):ttest selfishnew, by(type)
permute selfishnew (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==5), nodots reps(10000):ttest selfishnew, by(type)
permute selfishnew (r(mu_1)-r(mu_2)) if player==2&(type==3 | type==4), nodots reps(10000):ttest selfishnew, by(type)
permute selfishnew (r(mu_1)-r(mu_2)) if player==2&(type==3 | type==5), nodots reps(10000):ttest selfishnew, by(type)
permute selfishnew (r(mu_1)-r(mu_2)) if player==2&(type==4 | type==5), nodots reps(10000):ttest selfishnew, by(type)

//Do proposals differ?
mean proposal if player==2, over(type)
permute proposal (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==2), nodots reps(10000):ttest proposal, by(type)
permute proposal (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==3), nodots reps(10000):ttest proposal, by(type)
permute proposal (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==4), nodots reps(10000):ttest proposal, by(type)
permute proposal (r(mu_1)-r(mu_2)) if player==2&(type==1 | type==5), nodots reps(10000):ttest proposal, by(type)
permute proposal (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==3), nodots reps(10000):ttest proposal, by(type)
permute proposal (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==4), nodots reps(10000):ttest proposal, by(type)
permute proposal (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==5), nodots reps(10000):ttest proposal, by(type)
permute proposal (r(mu_1)-r(mu_2)) if player==2&(type==3 | type==4), nodots reps(10000):ttest proposal, by(type)
permute proposal (r(mu_1)-r(mu_2)) if player==2&(type==3 | type==5), nodots reps(10000):ttest proposal, by(type)
permute proposal (r(mu_1)-r(mu_2)) if player==2&(type==4 | type==5), nodots reps(10000):ttest proposal, by(type)

ksmirnov proposal if player==2&(type==1|type==2), by(type)
ksmirnov proposal if player==2&(type==1|type==3), by(type)
ksmirnov proposal if player==2&(type==1|type==4), by(type)
ksmirnov proposal if player==2&(type==1|type==5), by(type)
ksmirnov proposal if player==2&(type==2|type==3), by(type)
ksmirnov proposal if player==2&(type==2|type==4), by(type)
ksmirnov proposal if player==2&(type==2|type==5), by(type)
ksmirnov proposal if player==2&(type==3|type==4), by(type)
ksmirnov proposal if player==2&(type==3|type==5), by(type)
ksmirnov proposal if player==2&(type==4|type==5), by(type)

//Do devations differ?
//I. Deviation from actual proposal
//generate deviate1AS=effort1AS-proposal if proposal==1
//generate deviate3AS=effort3AS-proposal if proposal==3
//generate deviate5AS=effort5AS-proposal if proposal==5
//generate deviate7AS=effort7AS-proposal if proposal==7
//generate deviate9AS=effort9AS-proposal if proposal==9
mean deviate1AS if player==2, over(type)
mean deviate3AS if player==2, over(type)
mean deviate5AS if player==2, over(type)
mean deviate7AS if player==2, over(type)
mean deviate9AS if player==2, over(type)

//II. Deviation with strategy method

mean dev1stratAS if player==2, over(type)
mean dev3stratAS if player==2, over(type)
mean dev5stratAS if player==2, over(type)
mean dev7stratAS if player==2, over(type)
mean dev9stratAS if player==2, over(type)


//Regressions

//generate RSLow=0
//replace RSLow=1 if type==2
//generate RSHigh=0
//replace RSHigh=1 if type==3
//generate ESLow=0
//replace ESLow=1 if type==4
//generate ESHigh=0
//replace ESHigh=1 if type==5

//generate uniquesession=100*country+session

oprobit cho RSLow RSHigh ESLow ESHigh country gender age econ if player==2, cluster(un)
test RSLow=RSHigh
test ESLow=ESHigh
test RSLow=ESLow
test RSHigh=ESHigh

oprobit meanresponse RSLow RSHigh ESLow ESHigh country gender age econ if player==2, cluster(un)
test RSLow=RSHigh
test ESLow=ESHigh
test RSLow=ESLow
test RSHigh=ESHigh

oprobit proposal RSLow RSHigh ESLow ESHigh country gender age econ if player==2, cluster(un)
test RSLow=RSHigh
test ESLow=ESHigh
test RSLow=ESLow
test RSHigh=ESHigh

//And now with pooled high and pooled low status groups

//generate Low=0
//replace Low=1 if type1==2
//generate High=0
//replace High=1 if type1==3

oprobit cho Low High country gender age econ if player==2, cluster(un)
test Low=High

oprobit meanresponse Low High country gender age econ if player==2, cluster(un)
test Low=High

oprobit proposal Low High country gender age econ if player==2, cluster(un)
test Low=High

//Section 7
mean effort1AS effort3AS effort5AS effort7AS effort9AS if player==2, over(type1)

//generate absdev1stratAS=abs(dev1stratAS)
//generate absdev3stratAS=abs(dev3stratAS)
//generate absdev5stratAS=abs(dev5stratAS)
//generate absdev7stratAS=abs(dev7stratAS)
//generate absdev9stratAS=abs(dev9stratAS)

mean absdev1stratAS absdev3stratAS absdev5stratAS absdev7stratAS absdev9stratAS if player==2, over(type1)


//beliefs
mean clever if player==2, over(type)
permute clever (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==3), nodots reps(10000):ttest clever, by(type)
permute clever (r(mu_1)-r(mu_2)) if player==2&(type==4 | type==5), nodots reps(10000):ttest clever, by(type)
permute clever (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==4), nodots reps(10000):ttest clever, by(type)
permute clever (r(mu_1)-r(mu_2)) if player==2&(type==3 | type==5), nodots reps(10000):ttest clever, by(type)

mean ability if player==2, over(type)
permute ability (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==3), nodots reps(10000):ttest ability, by(type)
permute ability (r(mu_1)-r(mu_2)) if player==2&(type==4 | type==5), nodots reps(10000):ttest ability, by(type)
permute ability (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==4), nodots reps(10000):ttest ability, by(type)
permute ability (r(mu_1)-r(mu_2)) if player==2&(type==3 | type==5), nodots reps(10000):ttest ability, by(type)

mean deserving if player==2, over(type)
permute deserving (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==3), nodots reps(10000):ttest deserving, by(type)
permute deserving (r(mu_1)-r(mu_2)) if player==2&(type==4 | type==5), nodots reps(10000):ttest deserving, by(type)
permute deserving (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==4), nodots reps(10000):ttest deserving, by(type)
permute deserving (r(mu_1)-r(mu_2)) if player==2&(type==3 | type==5), nodots reps(10000):ttest deserving, by(type)

//beliefs
mean guess if player==2,over(type)
permute guess (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==3), nodots reps(10000):ttest guess, by(type)
permute guess (r(mu_1)-r(mu_2)) if player==2&(type==4 | type==5), nodots reps(10000):ttest guess, by(type)
permute guess (r(mu_1)-r(mu_2)) if player==2&(type==2 | type==4), nodots reps(10000):ttest guess, by(type)
permute guess (r(mu_1)-r(mu_2)) if player==2&(type==3 | type==5), nodots reps(10000):ttest guess, by(type)

//power analyses based on Dutch data
power twomeans 2.88 3.09, sd1(0.44) sd2(0.49)
